package com.atguigu.r2dbc.controller;

import com.atguigu.r2dbc.repositories.TeacherRepository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import com.atguigu.r2dbc.entity.TTeacher;

@RestController
public class TeacherController {
    private final TeacherRepository repository;

    public TeacherController(TeacherRepository repository) {
        this.repository = repository;
    }

    @PostMapping("/teacher")
    public Mono<TTeacher> createTeacher(@RequestBody TTeacher teacher) {
        return this.repository.save(teacher);
    }

    @GetMapping("/teacher")
    public Flux<TTeacher> getAllTeachers() {
        return repository.findAll();
    }
}
